public class Solution {
    public int largestAltitude(int[] gain) {
        int max = 0;
        int[] temp= new int[gain.length + 1];
        temp[0] = 0;
        for (int i = 0; i < gain.length; i++) {
            temp[i+1] = gain[i] + temp[i];
        }
        for (int i = 1; i < temp.length; i++) {
            max = Math.max(max, temp[i]);
        }
        return max;
    }

}
